/**
 * 详情对话框
 */
var CouponInfoDlg = {
    data: {
        id: "",
        company: "",
        account: "",
        couponName: "",
        preferentialContent: "",
        detail: "",
        generalAddress: "",
        quantity: "",
        remainingQuantity: "",
        valid: "",
        startTime: "",
        endTime: "",
        pic: "",
        type: "",
        externalLink: "",
        status: "",
        beginTime: "",
        finishTime: "",
        isDelete: "",
        createTime: "",
        updateTime: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    var upload = layui.upload;



    //多图片上传
    upload.render({
        elem: '#company'
        ,url: Feng.ctxPath + '/system/uploadFtp' //此处配置你自己的上传接口即可
        ,multiple: false
        ,done: function(res){
            $('#companyview').html('<img src="'+ res.data +'" alt="" class="layui-upload-img">');
            $('#companyPic').val(res.data);
            console.log(res)
        }
    });


    //多图片上传
    upload.render({
        elem: '#pic'
        ,url: Feng.ctxPath + '/system/uploadFtp' //此处配置你自己的上传接口即可
        ,multiple: false
        ,done: function(res){
            $('#picview').html('<img src="'+ res.data +'" alt="" class="layui-upload-img">');
            $('#picPic').val(res.data);
            console.log(res)
        }
    });




    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/coupon/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();

    $('#picview').html('<img src="'+ result.data.pic +'" alt="" class="layui-upload-img">');
    $('#companyview').html('<img src="'+ result.data.company +'" alt="" class="layui-upload-img">');

    form.val('couponForm', result.data);

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/coupon/editItem", function (data) {
            Feng.success("更新成功！");
            window.location.href = Feng.ctxPath + '/coupon'
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    $('#cancel').click(function(){
        window.location.href = Feng.ctxPath + '/coupon'
    });
});